<#import "/common/taglibs/spring.ftl" as spring/>
<#macro iconPicker name icon readonly="false">
    <div class="input-group">
        <input type="text" class="form-control" name="${name}" value="${icon!}"/>
        <span class="input-group-btn">
            <button id="icon-picker-${name}" class="btn btn-default" data-iconset="fontawesome" role="iconpicker"></button>
        </span>
    </div>
	<script>
    	// just make sure jquery load first
    	setTimeout(function(){
            <#if icon?? && icon != ''>
                $('#icon-picker-${name}').iconpicker("setIcon", "${(icon)?substring(3)}")
            </#if>
            $('#icon-picker-${name}').on('change', function(e) { 
                var icon = e.icon == 'empty'?"":"fa "+e.icon;
                $(":input[name='${name}']").val(icon);
            });
            
            if("true" == '${readonly}'){
            	$('#icon-picker-${name}').attr('disabled',"disabled");
            }
    	},500);
    </script>
</#macro>